package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.QuerySampleDTO;
import top.hcode.hoj.pojo.entity.course.Sample;
import top.hcode.hoj.service.admin.AdminSampleService;

/**
 * @author orangej
 * @since 2025/1/4
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AdminSampleController {

    private final AdminSampleService sampleService;

    @GetMapping("/admin/sample/list")
    public CommonResult<IPage<Sample>> getSampleList(QuerySampleDTO querySampleDTO) {
        return CommonResult.successResponse(sampleService.getSampleList(querySampleDTO));
    }

    @PostMapping("/admin/sample/save")
    public CommonResult<Sample> saveSample(@RequestBody Sample sample) {
        return CommonResult.successResponse(sampleService.saveSample(sample));
    }

    @PostMapping("/admin/sample/delete")
    public CommonResult<Void> deleteSample(@RequestBody BaseIdDTO dto) {
        sampleService.deleteSample(dto.getId());
        return CommonResult.successResponse();
    }

}
